/**
 * 
 */
package com.game.request;

import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;
import com.game.common.HandlerConst;
import com.game.log.LogEvent;
import com.game.log.LogType;
/**
 * 
 * @author lushouzhi
 * 
 */
public abstract class BaseRequest{
	protected IoSession ioSession;
	protected byte gameType;
	protected byte commandID;
	public BaseRequest(byte commandID) {
		this.commandID = commandID;
	}
	
	public IoSession getIoSession() {
		return ioSession;
	}


	public void setIoSession(IoSession ioSession) {
		this.ioSession = ioSession;
	}

	public byte getGameType() {
		return gameType;
	}


	public void setGameType(byte gameType) {
		this.gameType = gameType;
	}


	public byte getCommandID() {
		return commandID;
	}


	public void setCommandID(byte commandID) {
		this.commandID = commandID;
	}


	public abstract void setBody(IoBuffer buffer);
	
	
	public int getPlayerId() {
		Object key = ioSession.getAttribute(HandlerConst.ATTRIBUTE_KEY);
		if (key == null) {
			LogEvent.info("null attribute key", LogType.EXCEPTION);
			return -1;
		}
		int uid=-1;
		try {
			uid = Integer.parseInt(key.toString());
		} catch (Exception e) {
			return -1;
		}
		return uid;
	}
	
	
	
}
